#!/usr/bin/python
# -*- coding:utf-8 -*-
# @author  : xuexiaohua
# @time    : 2025/8/20 13:43
# @function: the script is used to do something.
# @version :
import pymysql
# 封装建立连接的对象
def get_conn():
    conn = pymysql.connect(
        host="litemall.hogwarts.ceshiren.com",
        port=3306,
        user="test",
        password="test123456",
        database="litemall",
        charset="utf8mb4"
    )
    return conn
# 执行sql语句
def execute_sql(sql):
    connect = get_conn()
    cursor = connect.cursor()
    cursor.execute(sql)  # 执行SQL
    record = cursor.fetchone()  # 查询记录
    return record

if __name__ == '__main__':
    # 查询查询user123这个用户的购物车有一个名称为 hogwarts1 的商品
    sql_res = execute_sql("select * from litemall_cart where "
                          "user_id=1 and deleted=0 and "
                          "goods_name='hogwarts1'")

    assert sql_res